package com.gitee.wsl.common.ui.draw.api

import androidx.compose.ui.geometry.Size

/**
 * Resizable allow to be notified of the new size.
 */
 interface Resizable {

    /**
     * Add a resize listener that will be notified in case of
     * new size.
     */
     fun addResizeListener(resizeListener: (Size) -> Unit): Unit
//     fun removeResizeListener( resizeListener:(Size)->Unit):Unit

}

/**
 * Resizable implementation to simplify the implementation
 * by delegation for all VizContainer.
 */
 class ResizableSupport: Resizable {

    private val resizeListeners = mutableListOf<(Size) -> Unit>()

    override fun addResizeListener(resizeListener: (Size) -> Unit) {
        resizeListeners.add(resizeListener)
    }

    /**
     * Notify the listeners of the new size.
     */
     fun notifyNewSize(value: Size) {
        resizeListeners.forEach {
            it(value)
        }
    }
}